package main

import (
	"fmt"
	"time"
)

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func hasCycle(head *ListNode) bool {
	if nil != head && nil != head.Next {
		slow := head.Next
		fast := head.Next
		for nil != fast && nil != fast.Next {
			slow = slow.Next
			fast = fast.Next.Next
			if slow == fast {
				return true
			}
		}

	}
	return false
}

func main() {
	start := time.Now()
	s, t := "rat", "car"
	dec := hasCycle(s, t)
	cost := time.Since(start)
	fmt.Println(dec)
	fmt.Println(cost)
}
